import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';

import packageConfig from '../package.json';

export const generateDocument = (app) => {
  const options = new DocumentBuilder()
    .setTitle(packageConfig.name)
    .setDescription(packageConfig.description)
    .setVersion(packageConfig.version)
    .addBearerAuth({
      type: 'http',
      description: 'jwt token',
    })
    .build();

  const document = SwaggerModule.createDocument(app, options);

  // json 文件地址: http://127.0.0.1:3000/api/doc-json
  SwaggerModule.setup('api/doc', app, document);
};
